import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type GroupDocument = Group & Document;

@Schema({
  timestamps: true,
})
export class Group {
  @Prop({ required: true })
  name: string;

  @Prop({ default: '' })
  description: string;

  @Prop({ default: '' })
  avatar: string;

  @Prop({ required: true })
  ownerId: string;

  @Prop({ type: [{ userId: String, role: String }], default: [] })
  members: Array<{
    userId: string;
    role: 'admin' | 'member';
  }>;

  @Prop({ type: [String], default: [] })
  admins: string[];

  @Prop({ default: true })
  isPublic: boolean;

  @Prop({ default: 500 })
  maxMembers: number;

  @Prop({ default: null })
  announcement: string;

  @Prop({ default: false })
  isDeleted: boolean;
}

export const GroupSchema = SchemaFactory.createForClass(Group);
